﻿<%@ Page Language="VB" MasterPageFile="~/masterpages/Main.master" AutoEventWireup="false" CodeFile="editAlbum.aspx.vb" Inherits="photoalbums_admin_editAlbum" title="Untitled Page" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <script type="text/javascript">
function addFileUploadBox()
    {
        if(!document.getElementById || !document.createElement)
        {
            return false;
        } 
        
        var uploadArea = document.getElementById("UploadField");
        if(!uploadArea)
        {
            return;
        }        
        
        var newLine = document.createElement("br");
        uploadArea.appendChild(newLine);
        var newLine2 = document.createElement("br");
        uploadArea.appendChild(newLine2);
        var newLine3 = document.createElement("br");
        uploadArea.appendChild(newLine3);
        var newLine4 = document.createElement("br");
        uploadArea.appendChild(newLine4);
        var newLine5 = document.createElement("br");
        uploadArea.appendChild(newLine5);
        
        // Create Title Box
        var newNameBox = document.createElement("input");
        newNameBox.type = "text";
        
        if(!addFileUploadBox.lastAssignedId)
        {
            addFileUploadBox.lastAssignedId = 1;
        }
        
        newNameBox.setAttribute("id", "txtImgName" + addFileUploadBox.lastAssignedId)
        newNameBox.setAttribute("name", "txtImgName" + addFileUploadBox.lastAssignedId)
        newNameBox.setAttribute("class", "adminTxtBox")
        // Create Title Label
        var newNameBoxLbl = document.createElement("label");
        
        if(!addFileUploadBox.lastAssignedId)
        {
            addFileUploadBox.lastAssignedId = 1;
        }
        
        newNameBoxLbl.setAttribute("id", "lblImgName" + addFileUploadBox.lastAssignedId)
        newNameBoxLbl.setAttribute("name", "lblImgName" + addFileUploadBox.lastAssignedId)
        newNameBoxLbl.setAttribute("style", "width: 120px; display: block; float: left;" + addFileUploadBox.lastAssignedId)
        // Create Caption box
        var newCapBox = document.createElement("input");
        newCapBox.type = "text";
        
        if(!addFileUploadBox.lastAssignedId)
        {
            addFileUploadBox.lastAssignedId = 1;
        }
        
        newCapBox.setAttribute("id", "txtCaption" + addFileUploadBox.lastAssignedId)
        newCapBox.setAttribute("name", "txtCaption" + addFileUploadBox.lastAssignedId)
        newCapBox.setAttribute("class", "adminTxtBox")
        
        // Create Caption Label
        var newCapBoxLbl = document.createElement("label");
        
        if(!addFileUploadBox.lastAssignedId)
        {
            addFileUploadBox.lastAssignedId = 1;
        }
        
        newCapBoxLbl.setAttribute("id", "lblCap" + addFileUploadBox.lastAssignedId)
        newCapBoxLbl.setAttribute("name", "lblCap" + addFileUploadBox.lastAssignedId)
        newCapBoxLbl.setAttribute("style", "width: 120px; display: block; float: left;" + addFileUploadBox.lastAssignedId)
        // Create Upload Box
        var newUploadBox = document.createElement("input");
        newUploadBox.type = "file";
        
        if(!addFileUploadBox.lastAssignedId)
        {
            addFileUploadBox.lastAssignedId = 1;
        }
        
        newUploadBox.setAttribute("id", "UploadFile" + addFileUploadBox.lastAssignedId)
        newUploadBox.setAttribute("name", "UploadFile" + addFileUploadBox.lastAssignedId)
        newUploadBox.setAttribute("class", "adminTxtBox")

        // Create File Label
        var newUploadBoxLbl = document.createElement("label");
        
        if(!addFileUploadBox.lastAssignedId)
        {
            addFileUploadBox.lastAssignedId = 1;
        }
        
        newUploadBoxLbl.setAttribute("id", "lblFile" + addFileUploadBox.lastAssignedId)
        newUploadBoxLbl.setAttribute("name", "lblFile" + addFileUploadBox.lastAssignedId)
        newUploadBoxLbl.setAttribute("style", "width: 120px; display: block; float: left;" + addFileUploadBox.lastAssignedId)

        uploadArea.appendChild(newNameBoxLbl);
        uploadArea.appendChild(newNameBox);
        uploadArea.appendChild(newLine2);
        
        uploadArea.appendChild(newCapBoxLbl);
        uploadArea.appendChild(newCapBox);
        uploadArea.appendChild(newLine3);

        uploadArea.appendChild(newUploadBoxLbl);
        uploadArea.appendChild(newUploadBox);
        uploadArea.appendChild(newLine4);

        document.getElementById("lblImgName" + addFileUploadBox.lastAssignedId).innerHTML = "Image Name: ";
        document.getElementById("lblCap" + addFileUploadBox.lastAssignedId).innerHTML = "Caption: ";
        document.getElementById("lblFile" + addFileUploadBox.lastAssignedId).innerHTML = "Select File To Upload: ";
        
        addFileUploadBox.lastAssignedId++;
                
    }
 
</script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div class="fullContent">
    
            <div style="float: right; width: 400px;">
<h3>Add Photo</h3>

        <p><asp:Label ID="lblMessage" runat="server" /></p>
    <asp:Panel ID="pnlNewImage" runat="server">
         <input type="button" id="buttonAdd" value="Add a File" onclick="addFileUploadBox();" /><br />
    </asp:Panel>
    <div id="UploadField">
        <div class="formRow">
            <span class="formField">
                <label for="txtImgName">Photo name:</label>
             </span>
            <asp:TextBox ID="txtImgName" runat="server" CssClass="adminTxtBox" Width="200px" />
        </div>
        
        
        
        <div class="formRow">
            <span class="formField">
                <label for="txtCaption">Caption:</label>
             </span>
            <asp:TextBox ID="txtCaption" runat="server" CssClass="adminTxtBox" 
                Height="17px" Width="200px" />
        </div>
        
        <div class="formRow">
            <span class="formField">
                <label for="txtCaption">File:</label>
             </span>
            <asp:FileUpload ID="fuPhoto" runat="server" CssClass="adminTxtBox" Width="200px" />
        </div>
        </div>
        
       
        <div class="formRow">
            <span class="formField">
                <label for="Submit">
                    &nbsp;</label></span>
            <asp:ImageButton ID="btnSubmit" runat="server" ImageUrl="/img/submit.gif" />
        </div>
        
        <div class="formRow">
            <span class="formField">
            <asp:Label ID="Label1" runat="server" /></span>
        </div>    
            <asp:Label ID="lblFileUpload" runat="server" /><br />
            <asp:Label ID="lblImgName" runat="server" /><br />
            <asp:Label ID="lblImgCap" runat="server" /><br />
    
    <asp:Label ID="lblFileUpload2" runat="server" /><br />
    <asp:Label ID="lblImgName2" runat="server" /><br />
    <asp:Label ID="lblImgCap2" runat="server" /><br />
    <asp:PlaceHolder ID="placeHolder" runat="server" />        
        </div>
        <h1>Edit Your Album</h1>
    
        <asp:ObjectDataSource ID="dsAlbum" runat="server" OldValuesParameterFormatString="{0}" 
            SelectMethod="GetAlbumByID" TypeName="MainDbTableAdapters.AlbumsTableAdapter" 
            UpdateMethod="UpdateAlbum" InsertMethod="Insert">
            <UpdateParameters>
                <asp:Parameter Name="UserID" Type="Int32" />
                <asp:Parameter Name="Title" Type="String" />
                <asp:Parameter Name="Caption" Type="String" />
                <asp:Parameter Name="Private" Type="Boolean" />
                <asp:Parameter Name="AlbumID" Type="Int32" />
            </UpdateParameters>
            <SelectParameters>
                <asp:QueryStringParameter DefaultValue="1" Name="AlbumID" 
                    QueryStringField="albumID" Type="Int32" />
            </SelectParameters>
            <InsertParameters>
                <asp:Parameter Name="UserID" Type="Int32" />
                <asp:Parameter Name="Title" Type="String" />
                <asp:Parameter Name="Caption" Type="String" />
                <asp:Parameter Name="Private" Type="Boolean" />
            </InsertParameters>
        </asp:ObjectDataSource>
        <asp:DetailsView ID="detAlbum" runat="server" Height="50px" Width="400px" 
            AutoGenerateRows="False" CellPadding="10" CellSpacing="5" GridLines="None" 
            DataSourceID="dsAlbum" DataKeyNames="AlbumID">
            <Fields>
                <asp:BoundField DataField="AlbumID" HeaderText="AlbumID" ReadOnly="True" />
                <asp:BoundField DataField="Title" HeaderText="Title" />
                <asp:BoundField DataField="Caption" HeaderText="Description" />
                <asp:TemplateField HeaderText="Private">
                    <EditItemTemplate>
                        <asp:CheckBox ID="chkPrivate" runat="server" Text="Make this album private" Checked='<%# Bind("Private") %>' OnCheckedChanged="Click_isPrivate" AutoPostBack="true" />
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:CheckBox ID="chkPrivate" runat="server" Text="Make this album private" Checked='<%# Bind("Private") %>' OnCheckedChanged="Click_isPrivate" AutoPostBack="true" />
                    </ItemTemplate>
                </asp:TemplateField>
                
                <asp:CommandField ShowEditButton="True" />
                
            </Fields>
        </asp:DetailsView>

        
        <h3>Images in this Album</h3>
        <a href="addPhoto.aspx?AlbumID=<%= AlbumID %>">Add Image</a>
        
            
        
           <asp:ListView ID="lstImages" runat="server" GroupItemCount="4" DataKeyNames="ImgID">
                <LayoutTemplate>
                     <div id="Div2" runat="server" class="pagedNav">
                        <asp:DataPager ID="lstPager"  PagedControlID="lstImages" runat="server" PageSize="16">
                            <Fields>
                                <asp:NextPreviousPagerField ShowPreviousPageButton="true" ShowNextPageButton="false" ShowFirstPageButton="True" ShowLastPageButton="false" />
                                <asp:NumericPagerField ButtonCount="30" ButtonType="Link"  RenderNonBreakingSpacesBetweenControls="true" />
                                <asp:NextPreviousPagerField ShowNextPageButton="true" ShowPreviousPageButton="false"  ShowFirstPageButton="false" ShowLastPageButton="True" />
                           </Fields>                
                        </asp:DataPager>
                     </div>
                
                        <asp:PlaceHolder ID="groupPlaceholder" runat="server" />
                    
                </LayoutTemplate>
                <GroupTemplate>
                    <ul id="Ul1" runat="server" class="imageBox clear">
                        <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
                    </ul>
                </GroupTemplate>
                <ItemTemplate>
                    <li id="Li1" runat="server">
                        <p id="P1" runat="server"><%#Eval("Title")%></p>
                        <a href="/img/imgGallery/<%#Eval("Filepath")%>" rel="lightbox[All]"><img src="/img/imgGallery/<%#Eval("Filepath")%>" width="200" alt="<%#Eval("Title")%>" rel="lightbox[img]" /></a>
                        <a href="editImage.aspx?ImgID=<%#Eval("ImgID")%>" class="right">Edit Image</a>
                        <asp:LinkButton ID="btnDeleteImage" runat="server" Text="Remove Image" CommandName="Select" CommandArgument='<%#Eval("ID") & "," & Eval("ImgID") & "," & Eval("Filepath")%>' />
                        <cc1:ConfirmButtonExtender ID="ajaxConfirm" runat="server" TargetControlID="btnDeleteImage" ConfirmText="Are you sure you want to delete this image?">
                        </cc1:ConfirmButtonExtender>
                       
                   </li>
                </ItemTemplate>
                
                
                <EmptyDataTemplate>
                    <p>No videos to display</p>
                </EmptyDataTemplate>
                
                
            </asp:ListView>         
        
        <asp:Label ID="lblCheck" runat="server" />
        <div class="clear"></div>
    </div>
</asp:Content>

